
import java.util.*;

/**
 * JZ79 判断是不是平衡二叉树
 * https://www.nowcoder.com/practice/8b3b95850edb4115918ecebdf1b4d222?tpId=13&tqId=11192&ru=/exam/oj
 */
class Solution
{
    static class TreeNode{
        TreeNode left;
        TreeNode right;
        int val;

        public TreeNode(int val)
        {
            this.val = val;
        }
    }

    public boolean IsBalanced_Solution (TreeNode pRoot)
    {
        return dps(pRoot) != -1;
    }

    public int dps(TreeNode pRoot)
    {
        if(pRoot == null) return 0;

        //左子树判断
        int left = dps(pRoot.left);
        if(left == -1) return -1;

        //右子树判断
        int right = dps(pRoot.right);
        if(right == -1) return -1;

        //左右子树均不为空
        return Math.abs(left - right) <= 1 ? Math.max(left,right) + 1 : -1;
    }
}

/**
 * DP10 最大子矩阵
 * https://www.nowcoder.com/practice/a5a0b05f0505406ca837a3a76a5419b3?tpId=230&tqId=40416&ru=/exam/oj
 */
public class Main
{
    public static void main(String[] args)
    {
        Scanner in = new Scanner(System.in);
        int  n = in.nextInt();
        int[][] dp = new int[n + 1][n + 1];

        for(int i = 1;i <= n;i++)
        {
            for(int j = 1;j <=n;j++)
            {
                int x = in.nextInt();
                dp[i][j] = dp[i][j-1] + dp[i-1][j] - dp[i-1][j-1] + x;
            }
        }

        //枚举子矩阵
        int maxSum = -1008611;
        for(int x1 = 1;x1 <=n;x1++)
        {
            for(int y1 = 1;y1 <= n;y1++)
            {
                for(int x2 = x1;x2 <= n;x2++)
                {
                    for(int y2 = y1;y2 <= n;y2++)
                    {
                        int tem = dp[x2][y2] - dp[x2][y1 -1] - dp[x1-1][y2] + dp[x1-1][y1-1];
                        maxSum = Math.max(maxSum,tem);
                    }
                }
            }
        }

        System.out.println(maxSum);
    }
}

/**
 * NC230830 小葱的01串
 * https://ac.nowcoder.com/acm/problem/230830
 */
 class Main2{
    public static void main(String[] args)
    {
        Scanner in = new Scanner(System.in);
        int n  = in.nextInt();
        char[] s = in.next().toCharArray();

        int sum[] = new int[2];
        for(int i = 0;i < n;i++){
            sum[s[i] - '0']++;
        }

        int count[] = new int[2];
        int left = 0,right = 0,t = n / 2;
        int ret = 0;
        while(right < n - 1){//防止重复计算
            //1.进入窗口
            count[s[right] - '0']++;

            //2.出窗口
            while(right - left + 1 > t){
                count[s[left++] - '0']--;
            }

            //3.判断
            if(right - left + 1 == t && count[0] == sum[0] /2 && count[1] == sum[1] /2){
                ret += 2;
            }
            right++;
        }

        System.out.println(ret);

    }
}

